<?php
namespace app\api\controller;


class Goods extends Base
{
    public function lists(){
        $where=[];
        $where["delete_time"]=['null',""];
        $where["isshow"]=1;
        $where['cate_id']=i("cate_id","请传入分类");
        $sort=i("sort","请传入sort","int");
        $page=i("page","","int");
        $order="";
        if($sort==0){
            $order="sort asc,";
        }
        else if($sort==1){
            $order="sales desc,";
        }
        else if($sort==2){
            $order="price asc,";
        }
        $list=model("goods")->where($where)->order("{$order}id asc")->limit(($page-1)*10,10)->select();
        return s($list);
    }

    public function get(){
        $id=i("id");
        $goods=model("goods")->where("id",$id)->find();
        return s($goods);
    }
    public function full(){
        $list_str=i("list");
        try{
            $list=json_decode($list_str,true);
        }catch (\Exception $e){

        }
        if(!is_array($list)){
            $list=[];
        }
        for($i=0;$i<count($list);$i++){
            $goods=model("goods")->where("id",$list[$i]['id'])->find()->toArray();
            $list[$i]=array_merge($list[$i],$goods);
        }
        return s($list);
    }
}
